package cn.tedu.dao;

import com.mysql.jdbc.Driver;

import java.sql.*;

public class JDBCDemo {
    public static void main(String[] args)  {
        try {
            //1.注册驱动
            Class.forName("com.mysql.jdbc.Driver");
//            DriverManager.registerDriver(new Driver());
            //2.建立链接
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu_spring","waqwb","qiu55555");
            //3.创建执行对象
            PreparedStatement ps = conn.prepareStatement("SELECT * FROM emp_info");
            //4.执行SQL语句，返回结果集
            ResultSet rs = ps.executeQuery();
            //5.遍历集合
            while (rs.next()){
                System.out.println(rs.getString("name"));
            }
            //6.关闭资源
            rs.close();
            ps.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
